﻿using ConfExpert.Forms.Base;
using ConfExpert.Forms.Rapor;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraReports.UI;
using DevTeam;

using System;
using System.Data;

namespace ConfExpert.Forms.SatinAlma.YeniYapi
{
    public partial class POFoyler : XForm
    {
        DataSet dsFoy;
        public POFoyler(DataSet dsFoy)
        {
            InitializeComponent();
            this.dsFoy = dsFoy;
        }

        private void POFoyler_Load(object sender, EventArgs e)
        {
            gvFoy.Init(dsFoy.Tables[0]);
            this.Text = "Oluşturulan Föyler";
            

            gvFoy.SetCaptions("POMpFoyId:Föy No", "UserId:Oluşturan", "OlusturulmaTarihi:Föy Tarihi","VendorId:Üretici");
            gvFoy.MakeColumnInvisible("POLinesIds");

            RepositoryItemHyperLinkEdit riPOId = new RepositoryItemHyperLinkEdit();
            riPOId.SingleClick = true;
            gvFoy.Columns["POMpFoyId"].ColumnEdit = riPOId;
            gvFoy.RowCellClick += gvFoy_RowCellClick;

            gvFoy.MakeReadOnly();
            gvFoy.BestFitColumns();
        }

        void gvFoy_RowCellClick(object sender, RowCellClickEventArgs e)
        {
            if (e.Column.FieldName == "POMpFoyId")
                FoyOlustur();
        }

      
        private void FoyOlustur()
        {
            int rowHandle = gvFoy.FocusedRowHandle;

            if (rowHandle > -1)
            {
                string pols = gvFoy.GetFocusedRowCellValue("POLinesIds").ToString();
                int vendorId = gvFoy.GetFocusedRowCellValue("VendorId").ToInt(-1);
                int foyId = gvFoy.GetFocusedRowCellValue("POMpFoyId").ToInt(-1);

                using (KumasSiparisFoyu ks = new KumasSiparisFoyu())
                {
                    DataSet ds = Session.DataManager.ExecuteDataSet("GetKumasSiparisFoy2", "", foyId, false, vendorId);
                    ks.TalepFoyuOlustur(ds);
                    ks.ShowPreviewDialog();
                }
            }
            else
                ShowInfoMessage("Lütfen bir satır seçin");


        }
    }
}